<template>
<div>
  <ul>
    <li v-for="item in userlist"><a-avatar
        size="normal"
        shape="square"
        style="background-color: #f56a00"
        :src="'data:image/jpeg;base64,'+item.base64Data">
    </a-avatar>
      {{item.nickname}}
      <a-popconfirm
          title="确认要更改用户状态吗?"
          ok-text="Yes"
          cancel-text="No"
          @confirm="confirm(item)"
          @cancel="cancel(item)"
      >
        <a-switch v-model:checked="item.isBanned" checked-children="禁言" un-checked-children="正常" />

      </a-popconfirm>
       </li>
  </ul>
</div>
</template>

<script>
import axios from "axios";
export default {
  name: "AdminUsers",
  data(){
    return{
      userlist:[]
    }
  },
  methods:{
    loadUsers(){
      axios.get("/admin/user/list").then(res => {
        console.log(res)
        this.userlist = res.data.data
      })
    },
    confirm(user){
      axios.put("/admin/user/updateIsBanned",user).then(res => {
        if(res.data.success){
          alert("修改成功")
        }
      })
    },
    cancel(user){
      user.isBanned = !user.isBanned
    }
  },
  created() {
    this.loadUsers()
  }
}
</script>

<style scoped>

</style>